Add missing SessionContext utility methods#1475
Add missing SessionContext utility methods#1475timsaucer wants to merge 1 commit intoapache:mainfrom
Conversation
Expose upstream DataFusion v53 utility methods: session_start_time, enable_ident_normalization, parse_sql_expr, execute_logical_plan, refresh_catalogs, remove_optimizer_rule, and table_provider. The add_optimizer_rule and add_analyzer_rule methods are omitted as the OptimizerRule and AnalyzerRule traits are not yet exposed to Python. Closes apache#1459. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR exposes additional SessionContext utility/introspection methods in the datafusion-python API to match capabilities available in upstream DataFusion v53 (Issue #1459), and adds unit tests to cover the new Python surface area.
Changes:
- Added Python
SessionContextwrappers for:session_start_time,enable_ident_normalization,parse_sql_expr,execute_logical_plan,refresh_catalogs,remove_optimizer_rule, andtable_provider. - Added corresponding Rust binding methods on
PySessionContextto call into DataFusion v53 APIs. - Added unit tests validating the new Python methods.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
python/datafusion/context.py |
Adds new SessionContext methods to the public Python API and wraps internal bindings (Expr, DataFrame, Table). |
crates/core/src/context.rs |
Exposes the underlying DataFusion SessionContext methods via the PyO3 PySessionContext bindings. |
python/tests/test_context.py |
Adds tests for the newly exposed SessionContext methods. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let provider = wait_for_future(py, self.ctx.table_provider(name))??; | ||
| Ok(PyTable { table: provider }) |
There was a problem hiding this comment.
table_provider() currently propagates DataFusion errors directly. For consistency with table() (which maps missing-table errors to KeyError), consider translating the “No table named …” / not-found case here to PyKeyError as well so Python users get a consistent exception type when looking up a non-existent table provider.
| let provider = wait_for_future(py, self.ctx.table_provider(name))??; | |
| Ok(PyTable { table: provider }) | |
| match wait_for_future(py, self.ctx.table_provider(name))? { | |
| Ok(provider) => Ok(PyTable { table: provider }), | |
| Err(err) => { | |
| let err_msg = err.to_string(); | |
| if err_msg.contains("No table named") || err_msg.contains("not found") { | |
| Err(pyo3::exceptions::PyKeyError::new_err(err_msg)) | |
| } else { | |
| Err(err.into()) | |
| } | |
| } | |
| } |
| def session_start_time(self) -> str: | ||
| """Return the session start time as an RFC 3339 formatted string.""" | ||
| return self.ctx.session_start_time() | ||
|
|
||
| def enable_ident_normalization(self) -> bool: | ||
| """Return whether identifier normalization (lowercasing) is enabled.""" | ||
| return self.ctx.enable_ident_normalization() | ||
|
|
There was a problem hiding this comment.
The PR description says it closes #1459, but the issue’s checklist also includes add_optimizer_rule and add_analyzer_rule. Those methods still don’t appear to be exposed in either the Rust bindings or the Python wrapper (no references found in the repo). Either add the remaining methods or adjust the PR description / linked issue closure to reflect the reduced scope.
Which issue does this PR close?
Closes #1459
Rationale for this change
These methods exist in the upstream repository but have not been exposed to Python.
What changes are included in this PR?
Add methods to the Python API
Add unit tests
Are there any user-facing changes?
New addition only.